package club.pchome.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import club.pchome.dto.UserInfoDto;
import club.pchome.mapper.AutoSignMapper;
import club.pchome.model.AutoSign;
import club.pchome.model.User;
import club.pchome.util.JsoupSignAdm;
import club.pchome.util.PageUtil;

@Service
public class AutoSignService {

	@Autowired
	JsoupSignAdm signAdm;
	
	@Autowired
	AutoSignMapper autoSignMapper;
	
	/**
	 * 获取可以签到的账户
	 * @return
	 */
	public List<AutoSign> getAccountList() {
		return autoSignMapper.getAccountList();
	}
	
	/**
	 * 获取用户数据
	 * @param pu
	 * @param map
	 * @return
	 */
	public PageUtil<UserInfoDto> getUserList(PageUtil<UserInfoDto> pu , Map<String, Object> map){
		pu.pageUtilHandle(autoSignMapper.getUserListCount(map));
		map.put("startRow", pu.getStartRow());
		map.put("pageSize", pu.getPageSize());
		pu.setDataList(autoSignMapper.getUserList(map));
		return pu;
	}
	
	public PageUtil<AutoSign> getAccountList(PageUtil<AutoSign> pu) {
		pu.setDataList(autoSignMapper.getAccountList());
		
		return pu;
	}
	
	/**
	 *	 获取可以签到的用户
	 * @return
	 */
	public List<AutoSign> getAccountAndSignList() {
		return autoSignMapper.getAccountAndSignList();
	}
	
	/**
	 * 核验当天已签到的用户并更新数据
	 * @return
	 */
	public List<AutoSign> checkAccountStatus() {
		return autoSignMapper.checkAccountStatus();
	}
	

	/**
	 *	 更新扫描信息
	 * @param autoSign
	 * @return
	 */
	public long updateAccountInfo(AutoSign autoSign) {
		return autoSignMapper.updateAccountInfo(autoSign);
	}
	
	/***
	 * 	记录短信
	 * @param autoSign
	 * @return
	 */
	public long updateSMSNum(AutoSign autoSign) {
		return autoSignMapper.updateSMSNum(autoSign);
	}
	
	/**
	 * 更新签到状态所有用户重置为可签到
	 * @return
	 */
	public long updateSignStatus() {
		return autoSignMapper.updateSignStatus();
	}
	
	/**
	 * 插入数据
	 * @param user
	 * @return
	 */
	public long insert(User user) {
		return autoSignMapper.insert(user);
	}
	
	public long getUserDataByPhone(User user) {
		return autoSignMapper.getUserDataByPhone(user);
	}
	
	
	/**
	 * 用户归属人查询
	 * @param userName
	 * @return
	 */
	public List<AutoSign> getUserHolder(String userName){
		
		return autoSignMapper.getUserHolder(userName);
	}

	/**
	 * 查询开通农场的用户
	 * @param userName
	 * @return
	 */
	public List<AutoSign> updateHolderNC(){

		return autoSignMapper.updateHolderNC();
	}
	
	/**
	 * 获取到期的该喂食的农场
	 * @return
	 */
	public List<UserInfoDto>getUserNC(){
		return autoSignMapper.getUserNC();
	}
 
	/**
	 * 按手机号查询用户
	 * @param userName
	 * @return
	 */
	public List<AutoSign> getUserPhone(String phoneList){
		
		return autoSignMapper.getUserPhone(phoneList);
	}
	
	/**按用户归属人及可售余额查询
	 * @param userName
	 * @param ksye
	 * @return
	 */
	public List<AutoSign> getUserHolderOrKYSE(String userName, int ksye){
		
		return autoSignMapper.getUserHolderOrKYSE(userName , ksye);
	}
	
	
	/**
	 * 当日发送短信数
	 * @return
	 */
	public int toDaySendSMSCount() {
		return autoSignMapper.toDaySendSMSCount();
	}
	
	/**自动签到是否过期
	 * @return
	 */
	public int isAutoSign() {
		return autoSignMapper.isAutoSign();
	}

	/**
	 * 自动喂养是否过期
	 * @return
	 */
	public int isAutoNC() {
		return autoSignMapper.isAutoNC();
	}
}
